package com.hzcx.app.simplechat.ui.setting.adapter;

import android.widget.CompoundButton;
import android.widget.Switch;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.ui.setting.bean.SettingFindMyWayBean;

import java.util.List;

public class SettingFindMyWayAdapter extends BaseQuickAdapter<SettingFindMyWayBean, BaseViewHolder> {

    private OnFindMyWaySwitchListener onFindMyWaySwitchListener;

    public SettingFindMyWayAdapter(@Nullable List<SettingFindMyWayBean> data) {
        super(R.layout.rv_item_setting_find_my_way, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SettingFindMyWayBean item) {
        helper.setText(R.id.tv_name, item.getName());

        Switch sh = helper.getView(R.id.switch_state);
        if (item.getList().getWay_sate() == 1) {
            sh.setChecked(true);
        } else {
            sh.setChecked(false);
        }

        sh.setOnCheckedChangeListener((compoundButton, b) -> {
            if (onFindMyWaySwitchListener != null) {
                onFindMyWaySwitchListener.switchChange(helper.getAdapterPosition());
            }
        });

    }

    public interface OnFindMyWaySwitchListener {
        void switchChange(int pos);
    }

    public void setOnFindMyWaySwitchListener(OnFindMyWaySwitchListener onFindMyWaySwitchListener) {
        this.onFindMyWaySwitchListener = onFindMyWaySwitchListener;
    }
}
